package routers

import (
	"git.multiverse.io/eventkit/dxc-server/config"
	"git.multiverse.io/eventkit/dxc-server/handler"
	"git.multiverse.io/eventkit/dxc-server/interceptor"
	"git.multiverse.io/eventkit/kit/codec"
	codec_json "git.multiverse.io/eventkit/kit/codec/json"
	codec_text "git.multiverse.io/eventkit/kit/codec/text"
	"git.multiverse.io/eventkit/kit/constant"
	"git.multiverse.io/eventkit/kit/handler/router"
)

func InitHandlerRouters(handlerRouter *router.HandlerRouter) error {
	handlerRouter.Router(config.Cfg.Service.TxnBeginTopicId,
		&handler.DxcHandler{},
		router.Method("TxnBegin"),
		router.HandlePost(constant.TxnBeginURLPath),
		router.WithCodec(codec.BuildCustomCodec(&codec_json.Encoder{}, &codec_text.Decoder{})),
		router.WithInterceptors(&interceptor.Interceptor{}),
	)
	handlerRouter.Router(config.Cfg.Service.TxnJoinTopicId,
		&handler.DxcHandler{},
		router.Method("TxnJoin"),
		router.HandlePost(constant.TxnJoinURLPath),
		router.WithCodec(codec.BuildCustomCodec(&codec_json.Encoder{}, &codec_text.Decoder{})),
		router.WithInterceptors(&interceptor.Interceptor{}),
	)
	handlerRouter.Router(config.Cfg.Service.TxnEndTopicId,
		&handler.DxcHandler{},
		router.Method("TxnEnd"),
		router.HandlePost(constant.TxnEndURLPath),
		router.WithCodec(codec.BuildCustomCodec(&codec_json.Encoder{}, &codec_text.Decoder{})),
		router.WithInterceptors(&interceptor.Interceptor{}),
	)
	return nil
}
